<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>我的简历</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>

    <link rel="stylesheet" href="../js/libs/sui/sm.min.css">
    <!--<link rel="stylesheet" href="../js/libs/sui/sm-extend.min.css">-->
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <link rel="stylesheet" href="../less/main.css"/>
    <style>

    </style>
    <script type="text/javascript" src='../js/libs/jquery-3.1.0.min.js' charset='utf-8'></script>
    <script type="text/javascript">
        var Zepto = jQuery;
    </script>
    <script type="text/javascript" src='../js/libs/sui/sm.min.js' charset='utf-8'></script>
    <!--<script type="text/javascript" src='../js/libs/sui/sm-extend.min.js' charset='utf-8'></script>-->
    <script type="text/javascript" src='../js/libs/sui/sm-city-picker.min.js' charset='utf-8'></script>
    <script type="text/javascript" src="../js/libs/juicer-min.js"></script>
    <script type="text/javascript" src="../js/libs/jquery.md5.js"></script>
    <script type="text/javascript" src="../js/api.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/common.js"></script>
</head>
<body>
<div class="page">
    <!-- 标题栏 -->
    <header class="bar bar-nav">
        <a class="icon iconfont c-white pull-left" onclick="javascript:api.closeWin();">&#xe61f;</a>
        <!--<a class="icon icon-refresh pull-right"></a>-->
        <h1 class="title">我的简历</h1>
    </header>
    <!-- 这里是页面内容区 -->
    <div class="content my-resume">
        <!--我的班级-->
        <!-- 头部-->
        <!--<div class="head-no-toolbar bg-self-green no-left-icon">-->
            <!--<span class="icon iconfont c-white p-l" onclick="javascript:api.closeWin();">&#xe61f;</span>-->
            <!--<span class="c-white t-center">我的简历</span>-->
        <!--</div>-->

        <!--内容区-->
        <div class="content-block">
            <div class="list-block m-t-0">
                <form id="resume_form" action="">
                    <input type="hidden" name="resume_id"/>
                    <table>
                        <tr>
                            <td>是否全职</td>
                            <td>
                                <input type="radio" name="fulltime_req" value="1" id="fulltime_req_1"/>
                                <label for="fulltime_req_1">是</label>
                                <input type="radio" name="fulltime_req" value="0" id="fulltime_req_0" style="margin-left: 10px;"/>
                                <label for="fulltime_req_0">否</label>
                            </td>
                        </tr>
                        <tr>
                            <td>最高学历</td>
                            <td>
                                <select name="education" class="c-gray">
                                    <option value="0">请选择</option>
                                    <option value="01">本科</option>
                                    <option value="02">大专</option>
                                    <option value="03">高中</option>
                                    <option value="04">初中</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>待遇要求</td>
                            <td>
                                <select name="pay_req" class="c-gray">
                                    <option value="0">请选择</option>
                                    <option value="2000元以下">2000元以下</option>
                                    <option value="2000-4000元">2000-4000元</option>
                                    <option value="4000-6000元">4000-6000元</option>
                                    <option value="6000-8000元">6000-8000元</option>
                                    <option value="8000-10000元">8000-10000元</option>
                                    <option value="10000-12000元">10000-12000元</option>
                                    <option value="12000元以上">12000元以上</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>工作地点</td>
                            <td>
                                <div id="location">请选择工作地点</div>
                                <input type="hidden" name="location_req"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">项目经验</td>
                        </tr>
                        <tr>
                            <td colspan="2" class="pos-rel">
                                <textarea class="c-gray" id="setArea1" name="project_exp" placeholder="请输入项目经验"></textarea>
                            <span class="wordWrap">
                                <var class="word word1">0</var>&nbsp;/&nbsp;<var class="wordMax"></var>
                            </span>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">工作经验</td>
                        </tr>
                        <tr>
                            <td colspan="2" class="pos-rel">
                                <textarea class="c-gray" id="setArea2" name="experience" placeholder="请输入工作经验"></textarea>
                            <span class="wordWrap">
                                <var class="word word2">0</var>&nbsp;/&nbsp;<var class="wordMax"></var>
                            </span>
                            </td>                    </tr>
                        <tr>
                            <td colspan="2">个人简历</td>

                        </tr>
                        <tr>
                            <td colspan="2" class="pos-rel">
                                <textarea class="c-gray" id="setArea3" name="personal_profile" placeholder="请输入个人简介"></textarea>
                            <span class="wordWrap">
                                <var class="word word3">0</var>&nbsp;/&nbsp;<var class="wordMax"></var>
                            </span>
                            </td>
                        </tr>
                    </table>
                    <div class="content-block">
                        <div class="row">
                            <div class="col-100">
                                <a id="save_btn" href="javascript:void(0);" class="button button-big button-fill button-success">保存</a>
                            </div>
                        </div>
                    </div>
                </form>
                <!--<form id="resume_form" action="">-->
                <!--<input type="hidden" name="resume_id"/>-->
                <!--<ul>-->
                <!--<li>-->
                <!--<div class="item-content">-->
                <!--<div class="item-media"><i class="icon icon-form-toggle"></i></div>-->
                <!--<div class="item-inner">-->
                <!--<div class="item-title label">是否全职</div>-->
                <!--<div class="item-input c-gray">-->
                <!--<input type="radio" name="fulltime_req" value="1" id="fulltime_req_1"/>-->
                <!--<label for="fulltime_req_1">是</label>-->
                <!--<input type="radio" name="fulltime_req" value="0" id="fulltime_req_0" style="margin-left: 10px;"/>-->
                <!--<label for="fulltime_req_0">否</label>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
                <!--</li>-->
                <!--<li>-->
                <!--<div class="item-content">-->
                <!--<div class="item-media"><i class="icon icon-form-gender"></i></div>-->
                <!--<div class="item-inner">-->
                <!--<div class="item-title label">最高学历</div>-->
                <!--<div class="item-input p-l-0">-->
                <!--<select name="education" class="c-gray p-l-0">-->
                <!--<option value="0">请选择</option>-->
                <!--<option value="01">本科</option>-->
                <!--<option value="02">大专</option>-->
                <!--<option value="03">高中</option>-->
                <!--<option value="04">初中</option>-->
                <!--</select>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
                <!--</li>-->
                <!--<li>-->
                <!--<div class="item-content">-->
                <!--<div class="item-media"><i class="icon icon-form-gender"></i></div>-->
                <!--<div class="item-inner">-->
                <!--<div class="item-title label">待遇要求</div>-->
                <!--<div class="item-input">-->
                <!--<select name="pay_req" class="c-gray p-l-0">-->
                <!--<option value="0">请选择</option>-->
                <!--<option value="2000元以下">2000元以下</option>-->
                <!--<option value="2000-4000元">2000-4000元</option>-->
                <!--<option value="4000-6000元">4000-6000元</option>-->
                <!--<option value="6000-8000元">6000-8000元</option>-->
                <!--<option value="8000-10000元">8000-10000元</option>-->
                <!--<option value="10000-12000元">10000-12000元</option>-->
                <!--<option value="12000元以上">12000元以上</option>-->
                <!--</select>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
                <!--</li>-->
                <!--<li>-->
                <!--<div class="item-content">-->
                <!--<div class="item-media"><i class="icon icon-form-gender"></i></div>-->
                <!--<div class="item-inner">-->
                <!--<div class="item-title label">工作地点</div>-->
                <!--<div class="item-input">-->
                <!--<div id="location">请选择工作地点</div>-->
                <!--<input type="hidden" name="location_req"/>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
                <!--</li>-->
                <!--<li class="align-top my-resume-area">-->
                <!--<div class="item-content">-->
                <!--<div class="item-media"><i class="icon icon-form-comment"></i></div>-->
                <!--<div class="item-inner">-->
                <!--<div class="item-title label">项目经验</div>-->
                <!--<div class="item-input">-->
                <!--<textarea id="setArea1" name="project_exp" placeholder="请输入项目经验"></textarea>-->
                <!--<span class="wordWrap">-->
                <!--<var class="word word1">0</var>&nbsp;/&nbsp;<var class="wordMax"></var>-->
                <!--</span>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
                <!--</li>-->
                <!--<li class="align-top my-resume-area">-->
                <!--<div class="item-content">-->
                <!--<div class="item-media"><i class="icon icon-form-comment"></i></div>-->
                <!--<div class="item-inner">-->
                <!--<div class="item-title label">工作经验</div>-->
                <!--<div class="item-input">-->
                <!--<textarea id="setArea2" name="experience" placeholder="请输入工作经验"></textarea>-->
                <!--<span class="wordWrap">-->
                <!--<var class="word word2">0</var>&nbsp;/&nbsp;<var class="wordMax"></var>-->
                <!--</span>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
                <!--</li>-->
                <!--<li class="align-top my-resume-area">-->
                <!--<div class="item-content">-->
                <!--<div class="item-media"><i class="icon icon-form-comment"></i></div>-->
                <!--<div class="item-inner">-->
                <!--<div class="item-title label">个人简介</div>-->
                <!--<div class="item-input">-->
                <!--<textarea id="setArea3" name="personal_profile" placeholder="请输入个人简介"></textarea>-->
                <!--<span class="wordWrap">-->
                <!--<var class="word word3">0</var>&nbsp;/&nbsp;<var class="wordMax"></var>-->
                <!--</span>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
                <!--</li>-->
                <!--</ul>-->
                <!--</form>-->
            </div>
            <!--<div class="content-block">-->
            <!--<div class="row">-->
            <!--<div class="col-100">-->
            <!--<a id="save_btn" href="javascript:void(0);" class="button button-big button-fill button-success">保存</a>-->
            <!--</div>-->
            <!--</div>-->
            <!--</div>-->
        </div>

    </div>
</div>


<script type="text/javascript">
    apiready = function () {
        juicer.set({
            'tag::operationOpen': '{@',
            'tag::operationClose': '}',
            'tag::interpolateOpen': '&{',
            'tag::interpolateClose': '}',
            'tag::noneencodeOpen': '$${',
            'tag::noneencodeClose': '}',
            'tag::commentOpen': '{#',
            'tag::commentClose': '}',
            'strip': false,
            'cache': false
        });

        //***********************前端*************************/
        (function () {
            // 实时计算剩余字数函数
            function textareaNum(textareaNode, numNode, max) {
                var area = $(textareaNode)
                var numNode = $(numNode);
                area.attr('maxlength', max);
                numNode.next().text(max);
                area.on('input propertychange', function () {
                    var _value = $(this).val().replace(/\n/gi, "");
                    numNode.text(_value.length);
                });
            }

            // 调用计算字数函数
            textareaNum("#setArea1", ".my-resume .word1", 1000);
            textareaNum("#setArea2", ".my-resume .word2", 1000);
            textareaNum("#setArea3", ".my-resume .word3", 200);

            //工作地点获取焦点 进入选择省市 页面
            $('#location').click(function () {
                openWin("location", "location.html", null);
            });
        })();
        //***********************前端*************************/

        //***********************[后端]*************************/
        // 简历 ID
        var $resumeId = $("#resume_form input[name='resume_id']");
        // 是否全职
        // var $fulltimeReq = $("#resume_form input[name='fulltime_req']");
        // 最高学历
        var $education = $("#resume_form select[name='education']");
        // 待遇要求
        var $payReq = $("#resume_form select[name='pay_req']");
        // 工作地点
        var $locationReq = $("#resume_form input[name='location_req']");
        // 项目经验
        var $projectExp = $("#resume_form textarea[name='project_exp']");
        // 工作经验
        var $experience = $("#resume_form textarea[name='experience']");
        // 个人简介
        var $personalProfile = $("#resume_form textarea[name='personal_profile']");
        // 查询学生简历 SQL
        var resumeSql = "SELECT T1.*, T2.AREA_CODE, T2.PROVINCE, T2.CITY FROM E_RESUME T1 ";
        resumeSql += "LEFT JOIN W_AREA T2 ON T1.LOCATION_REQ = T2.AREA_CODE WHERE T1.STUDENT_ID = '{0}'";
        // 创建学生简历 SQl
        var saveResumeSql = "INSERT INTO E_RESUME(STUDENT_ID, EDUCATION, PAY_REQ, LOCATION_REQ, FULLTIME_REQ, PROJECT_EXP, EXPERIENCE, PERSONAL_PROFILE, CREATE_DATE) ";
        saveResumeSql += "VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', NOW())";
        // 更新学生简历 SQL
        var updateResumeSql = "UPDATE E_RESUME T SET T.EDUCATION = '{0}', T.PAY_REQ = '{1}', T.LOCATION_REQ = '{2}', T.FULLTIME_REQ = '{3}', ";
        updateResumeSql += "T.PROJECT_EXP = '{4}', T.EXPERIENCE = '{5}', T.PERSONAL_PROFILE = '{6}', T.CREATE_DATE = NOW() WHERE T.RESUME_ID = '{7}'";
        // 登录的学生信息
        var stuInfo = getLoginStudentInfo();
        // 简历标志：false-不可以保存/更新；true-可以保存/更新
        var resumeFlag = false;
        // 保存标志：false-不可以保存；true-可以保存
        var saveFlag = true;
        // 更新标志：false-不可以更新；true-可以更新
        var updateFlag = true;

        // 监听选择城市的事件
        api.addEventListener({
            name: "selectCityEvent"
        }, function(ret, err) {
            if (isObject(ret) && isObject(ret.value)) {
                var value = ret.value;

                $("#resume_form input[name='location_req']").val(value.areaCode);
                $("#location").html(value.province + "&nbsp;&nbsp;" + value.city);
            }
        });

        if (isObject(stuInfo) && isNumber(stuInfo.STUDENT_ID)) {
            var tmpResumeSql = resumeSql.format(stuInfo.STUDENT_ID);

            // 查询学生简历
            dbQuery(1, 1, tmpResumeSql, true, function(ret, err) {
                // 查询成功
                if (isObject(ret) && (ret.statusCode == 0)) {
                    resumeFlag = true;

                    // 已有简历
                    if (isArray(ret.result) && (ret.result.length > 0)) {
                        // 获取简历
                        var resume = ret.result[0];

                        $resumeId.val(resume.RESUME_ID);
                        $("#resume_form input[name='fulltime_req'][value='{0}']".format(resume.FULLTIME_REQ)).attr("checked", true);
                        $education.find("option[value='{0}']".format(resume.EDUCATION)).attr("selected", true);
                        $payReq.find("option[value='{0}']".format(resume.PAY_REQ)).attr("selected", true);
                        $locationReq.val(resume.AREA_CODE);
                        if (isEmpty(resume.CITY)) {
                            $("#location").html(resume.PROVINCE + "&nbsp;&nbsp;" + resume.PROVINCE);
                        } else {
                            $("#location").html(resume.PROVINCE + "&nbsp;&nbsp;" + resume.CITY);
                        }
                        $projectExp.val(resume.PROJECT_EXP);
                        $experience.val(resume.EXPERIENCE);
                        $personalProfile.val(resume.PERSONAL_PROFILE);

                        //********************[前端补充]********************/
                        var textareaVal1 = $projectExp.val().replace(/\n/gi, "");
                        $projectExp.next().find(".word1").text(textareaVal1.length);
                        var textareaVal2 = $experience.val().replace(/\n/gi, "");
                        $experience.next().find(".word2").text(textareaVal2.length);
                        var textareaVal3 = $personalProfile.val().replace(/\n/gi, "");
                        $personalProfile.next().find(".word3").text(textareaVal3.length);
                        //********************[/前端补充]********************/
                    }

                    // 查询失败
                } else {
                    resumeFlag = false;
                }
            });
        }

        // 保存
        $("#save_btn").click(function() {
            var $fulltimeReq = $("#resume_form input[name='fulltime_req']:checked");

            if (isEmpty($fulltimeReq.val())) {
                toast("请选择是否全职");

                $fulltimeReq.focus();

                return;
            }

            if (isEmpty($education.val()) || ($education.val() == "0")) {
                toast("请选择最高学历");

                $education.focus();

                return;
            }

            if (isEmpty($payReq.val()) || ($payReq.val() == "0")) {
                toast("请选择待遇要求");

                $payReq.focus();

                return;
            }

            if (isEmpty($locationReq.val())) {
                toast("请选择工作地点");

                $locationReq.focus();

                return;
            }

            if (isEmpty($projectExp.val())) {
                toast("请输入项目经验");

                $projectExp.focus();

                return;
            }

            if ($projectExp.val().length > 1000) {
                toast("项目经验不能超过1000字");

                $projectExp.focus();

                return;
            }

            if (isEmpty($experience.val())) {
                toast("请输入工作经验");

                $experience.focus();

                return;
            }

            if ($experience.val().length > 1000) {
                toast("工作经验不能超过1000字");

                $experience.focus();

                return;
            }

            if (isEmpty($personalProfile.val())) {
                toast("请输入个人简介");

                $personalProfile.focus();

                return;
            }

            if ($personalProfile.val().length > 200) {
                toast("个人简介不能超过200字");

                $personalProfile.focus();

                return;
            }

            if (resumeFlag && isObject(stuInfo) && isNumber(stuInfo.STUDENT_ID)) {
                // 创建简历
                if (isEmpty($resumeId.val())) {
                    if (saveFlag) {
                        var tmpSaveResumeSql = saveResumeSql.format(stuInfo.STUDENT_ID, $education.val(), $payReq.val(), $locationReq.val(), $fulltimeReq.val(), $projectExp.val(), $experience.val(), $personalProfile.val());

                        resumeFlag = false;
                        saveFlag = false;
                        updateFlag = false;

                        dbExecute(tmpSaveResumeSql, true, function(ret, err) {
                            // 执行成功
                            if (isObject(ret) && (ret.statusCode == 0)) {
                                toast("保存成功");

                                var tmpResumeSql = resumeSql.format(stuInfo.STUDENT_ID);

                                // 查询学生简历，目的是获取简历 ID
                                dbQuery(1, 1, tmpResumeSql, true, function(ret, err) {
                                    // 查询成功
                                    if (isObject(ret) && (ret.statusCode == 0)) {
                                        resumeFlag = true;

                                        // 已有简历
                                        if (isArray(ret.result) && (ret.result.length > 0)) {
                                            saveFlag = false;
                                            updateFlag = true;

                                            // 获取简历
                                            var resume = ret.result[0];

                                            // 设置简历 ID
                                            $resumeId.val(resume.RESUME_ID);

                                            // 未有简历
                                        } else {
                                            saveFlag = true;
                                            updateFlag = false;
                                        }

                                        // 查询失败
                                    } else {
                                        resumeFlag = false;
                                        saveFlag = false;
                                        updateFlag = false;
                                    }
                                });

                                // 执行失败
                            } else {
                                toast("保存失败，稍后再试");

                                resumeFlag = true;
                                saveFlag = true;
                                updateFlag = false;
                            }
                        });
                    }

                    // 更新简历
                } else {
                    if (updateFlag) {
                        var tmpUpdateResumeSql = updateResumeSql.format($education.val(), $payReq.val(), $locationReq.val(), $fulltimeReq.val(), $projectExp.val(), $experience.val(), $personalProfile.val(), $resumeId.val());

                        resumeFlag = false;
                        saveFlag = false;
                        updateFlag = false;

                        dbExecute(tmpUpdateResumeSql, true, function(ret, err) {
                            resumeFlag = true;
                            saveFlag = false;
                            updateFlag = true;

                            // 执行成功
                            if (isObject(ret) && (ret.statusCode == 0)) {
                                toast("更新成功");

                                // 执行失败
                            } else {
                                toast("更新失败，稍后再试");
                            }
                        });
                    }
                }
            }
        });
        //***********************[/后端]*************************/
    };
</script>
</body>
</html>
